<template>
	<view class="tally_buy">
		<view class="close" @click="close">
			<image src="@/static/images/close.png"></image>
		</view>
		<view class="title">{{data_info.name}}</view>
		<view class="head">购买数量</view>
		<view class="number_box">
			<uv-number-box v-model="form.copies" :min="0" :max="max" @overlimit="overlimit">
				<template v-slot:minus>
					<image src="@/static/images/a1.png" class="oper_img"></image>
				</template>
				<template v-slot:input>
					<view class="value">{{form.copies}}</view>
				</template>
				<template v-slot:plus>
					<image src="@/static/images/a2.png" class="oper_img"></image>
				</template>
			</uv-number-box>
		</view>
		<view class="balance">
			<view class="item">
				<text class="key">余额：</text>
				<text class="value">{{props.data.balance}}</text>
			</view>
			<view class="item">
				<text class="key">当前可购买：</text>
				<text class="value">{{max}}份</text>
			</view>
		</view>
		<view class="head">交易密码</view>
		<input type="text" password placeholder="请输入支付密码" class="code_input" v-model="form.password">
		<!-- <view class="code_view">
			<uv-code-input mode="box" color="#fff" dot @finish="finish"></uv-code-input>
		</view> -->
		<view class="head">购买说明：</view>
		<view class="parse_view">
			<uv-parse :content="data_info.content"></uv-parse>
		</view>
		<view class="btn">
			<view @click="submit">确定</view>
		</view>
	</view>
</template>

<script setup>
	import {
		crowdfundingInfo
	} from "@/request/api";
	import {
		ref,
		reactive,
		onUnmounted
	} from 'vue';
	import useStore from "@/stores/index.js";
	const {
		useUserStore
	} = useStore();
	const props = defineProps({
		data: Object,
	});
	const emit = defineEmits(["close", "submit"]);

	const balance = useUserStore.user_info.balance;

	const data_info = ref({});
	let max = ref(0);
	const get_deta = async () => {
		let {
			info
		} = await crowdfundingInfo({
			id: props.data.id
		});
		data_info.value = info;
		max.value = info.copies_surplus;
	};
	get_deta();

	const overlimit = (type) => {
		if (type == "minus") {
			uni.$uv.toast("已经是最小值了");
		}
		if (type == "plus") {
			uni.$uv.toast("已经是最大值了");
		}
	};
	const close = () => emit("close");

	const form = reactive({
		id: props.data.id,
		copies: 0,
		password: ""
	});
	const submit = () => emit("submit", form);
	onUnmounted(() => form.password = "");
</script>

<style scoped lang="scss">
	$tabsHeight: 114rpx;

	.tally_buy {
		padding: 40rpx 30rpx;
		box-sizing: border-box;
		background: #2F2F2F;

		.close {
			position: absolute;
			right: 30rpx;
			top: 20rpx;
			z-index: 2;

			image {
				width: 44rpx;
				height: 44rpx;
			}
		}

		.title {
			text-align: center;
			color: #FFFFFF;
			font-size: 40rpx;
			font-weight: bold;
		}

		.head {
			color: #CCCCCC;
			font-size: 32rpx;
			font-weight: bold;
			padding-left: 20rpx;
			box-sizing: border-box;
			position: relative;

			&::after {
				content: "";
				width: 5rpx;
				height: 32rpx;
				background: #DDF247;
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
			}
		}

		.code_input {
			height: 78rpx;
			text-align: center;
			color: #999999;
			font-size: 36rpx;
			border-radius: 10rpx;
			margin: 30rpx 0 40rpx;
			background: #2B2B2B;
		}

		.number_box {
			padding: 50rpx 10rpx 30rpx;
			box-sizing: border-box;

			.uv-number-box {
				justify-content: space-between;
			}

			.oper_img {
				width: 78rpx;
				height: 78rpx;
			}

			.value {
				width: 480rpx;
				height: 78rpx;
				line-height: 78rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 50rpx;
				border-radius: 10rpx;
				background: #2B2B2B;
			}
		}

		.balance {
			padding: 0 10rpx 50rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;

			.item {
				display: flex;
				align-items: center;

				.key {
					color: #999999;
					font-size: 28rpx;
				}

				.value {
					color: #FFFFFF;
					font-size: 28rpx;
					font-weight: bold;
				}
			}
		}

		.code_view {
			padding: 30rpx 0 40rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: center;
		}

		.parse_view {
			color: #666666;
			font-size: 32rpx;
			font-weight: bold;
			padding: 32rpx 0 80rpx;
			box-sizing: border-box;
		}

		.btn {
			padding: 0 35rpx;
			box-sizing: border-box;

			view {
				width: 100%;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #111111;
				font-size: 28rpx;
				font-weight: bold;
				border-radius: 20rpx;
				background: #DDF247;
			}
		}
	}
</style>